package com.qclix.inv;

import java.util.Calendar;
import java.util.List;
import java.util.SortedSet;

/**
 * Description of the services available for invoices
 */
public interface InvoiceService {
    /**
     * Returns all the clients
     * @return
     */
    List<Client> getClients();

    /**
     * Stores a new client
     * @param client
     * @return
     */
    Client addClient(Client client);

    /**
     * Tells if the system contains a least on client
     * @return true if the system contains one or more clients, false otherwise
     */
    boolean hasAtLeastOneClient();

    /**
     * Stores a new invoice
     * @param invoice
     */
    void addInvoice(Invoice invoice);

    /**
     * Returns the client the last invoice was destined to
     * @return a client or null if there are no invoice
     */
    Client getLastInvoicedClient();

    /**
     *
     * @return
     */
    List<Invoice> getLastInvoices();

    /**
     * Returns the last invoices (last by dates)
     * @param number the number of invoices to return
     * @return a list of invoices, containing a most number elements. The list size might be smaller than number and
     * even 0 if there is no invoices in the storage
     */
    List<Invoice> getLastInvoices(int number);

    /**
     * Returns the invoice with the given number
     * @param number
     * @return an invoice or null if no invoice has that number
     */
    Invoice getInvoice(String number);

    /**
     * Returns the timesheet with the given id
     * @param id
     * @return a timesheet, or null if no timesheet has this id
     */
    Timesheet getTimesheet(long id);

    /**
     * Returns the timesheet that covers the given month
     * @param month
     * @param year
     * @return returns a timesheet, or null if no timesheet covers that month
     */
    Timesheet getTimesheet(int month, int year);

    /**
     * Stores a new timesheet
     * @param timesheet
     */
    void saveTimesheet(Timesheet timesheet);

    /**
     * Returns a list of the holidays
     * @return
     */
    List<Holiday> getHolidays();

    /**
     * Returns a sorted set of every first days of existing timesheets
     * @return
     */
    SortedSet<Calendar> getTimesheetFirstDays();

    /**
     * Returns the contract that has the given reference.
     * @param reference
     * @return the contract if it exists, null otherwise
     */
    Contract getContract(String reference);

    /**
     * Returns all the existing contracts
     * @return
     */
    List<Contract> getAllContracts();

    /**
     * Returns all the contract with the given client
     *
     * @param client
     * @return a set of contract, eventually empty
     */
    List<Contract> getContracts(Client client);

    /**
     * Returns the contract the given invoice is related to
     * @param invoice
     * @return a Contract or null if the invoice is not related to any contract
     */
    Contract getContract(Invoice invoice);

    /**
     * Stores a new contract
     * @param contract
     */
    void saveContract(Contract contract);

    /**
     * Returns the contracts which are active on a certain date
     * @param cal
     * @return a list, eventually empty, of contracts
     */
    List<Contract> getActiveContracts(Calendar cal);
}
